﻿//
// Created by francklinson on 2021/3/16.
//

#include <iostream>

// Note: some implementations require double instead of long double
long double probability(unsigned int numbers, unsigned int  picks);

int main()
{
    using namespace std;
    unsigned int total, choices;
    cout << "Enter the total number of choices on the game card and\n"
            "the number of picks allowed:\n";
    while ((cin >> total >> choices) && choices <= total)
    {
        cout << "You have one chance in ";
        cout << probability(total, choices); // compute the odds
        cout << " of winning.\n";
        cout << "Next two numbers (q to quit): ";
    }
    cout << "bye\n";
    return 0;
}

// the following function calculates the probability of picking picks
// numbers correctly from numbers choices
long double probability(unsigned int numbers, unsigned int picks)
{
    long double result = 1.0; // here come some local variables
    for (; picks > 0; numbers--, picks--)
        result = result * numbers / picks;
    return result;
}